package ${myPackage}.service.impl;

import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ${myPackage}.util.Paging;
import ${myPackage}.criteria.${className}Criteria;
import ${myPackage}.domain.${className};
import ${myPackage}.service.${className}Service;
import ${myPackage}.dao.${className}Mapper;

@Service
public class ${className}ServiceImpl implements ${className}Service{
	
	@Autowired
    private ${className}Mapper $!{lowerName}Mapper;
    
	public ${className} selectByPrimaryKey(Integer ${primarykey}){
		return $!{lowerName}Mapper.selectByPrimaryKey(${primarykey});
	}
	
	public List<${className}> selectByCriteria(${className}Criteria criteria){
		return $!{lowerName}Mapper.selectByCriteria(criteria);
	}
	
	public int deleteByPrimaryKey(Integer ${primarykey}){
		int actualRowsAffected = 0;
		
		${className} _old${className} = $!{lowerName}Mapper.selectByPrimaryKey(${primarykey});
		
		if (_old${className} != null) {
			actualRowsAffected = $!{lowerName}Mapper.deleteByPrimaryKey(${primarykey});
		}
		
		return actualRowsAffected;
	}
	
	public int deleteByCriteria(${className}Criteria criteria){
		int actualRowsAffected = 0;
		
		List<${className}> _old${className} = $!{lowerName}Mapper.selectByCriteria(criteria);
		
		if (_old${className}.size() != 0) {
			actualRowsAffected = $!{lowerName}Mapper.deleteByCriteria(criteria);
		}
		
		return actualRowsAffected;
	}
	
	public int insert(${className} ${lowerName}){
		return $!{lowerName}Mapper.insert(${lowerName});
	}
	
	public int updateByPrimaryKeySelective(${className} ${lowerName}){
		int actualRowsAffected = 0;
		
		int advertisingId = ${lowerName}.get${primarykeyGet}();

		${className} _old${className} = $!{lowerName}Mapper.selectByPrimaryKey(advertisingId);
		
		if (_old${className} != null) {
			actualRowsAffected = $!{lowerName}Mapper.updateByPrimaryKeySelective(${lowerName});
		}
		
		return actualRowsAffected;
	}
	
	public int updateByPrimaryKey(${className} ${lowerName}){
		int actualRowsAffected = 0;
		
		int advertisingId = ${lowerName}.get${primarykeyGet}();

		${className} _old${className} = $!{lowerName}Mapper.selectByPrimaryKey(advertisingId);
		
		if (_old${className} != null) {
			actualRowsAffected = $!{lowerName}Mapper.updateByPrimaryKey(${lowerName});
		}
		
		return actualRowsAffected;
	}
	
	public List<${className}> selectByPage(${className}Criteria criteria) {
		int totalResults = $!{lowerName}Mapper.countByCriteria(criteria);
		Paging paging = criteria.getPaging();
		paging.setTotalResults(totalResults);
		
		return $!{lowerName}Mapper.selectByPage(criteria,new RowBounds(paging.getFirstResult(),paging.getMaxResults()));
	}
	
	public int countByCriteria(${className}Criteria criteria){
		return $!{lowerName}Mapper.countByCriteria(criteria);
	}
	
}
